Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promisize

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promisize

Easily support both callbacks and promises in your js lib

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

promisize Build Status npm

Easily support both callbacks and promises in your js lib

promisize takes your function's callback argument and returns a new callback with a promise property. When the new callback is called, it either calls the original callback or if no callback was given it fulfills the promise. promisize is lightweight and does not include any promise shims or dependencies but instead uses the globally defined Promise. If Promise is not defined (i.e. no native promise support) then callbacks still work as they would without promisize.

Usage

var promisize = require('promisize')

function someAsyncFunction (cb) {
  cb = promisize(cb)

  // Do some async stuff then
  setTimeout(function () {
    cb(null, 'foobar')
  })

  // Undefined if there is no Promise support
  // or if the original callback was defined
  return cb.promise
}

API

var cb = promisize(function callback (err, result) {})

promisize takes a nodejs style callback and returns another nodejs style callback. When the returned callback is called it either calls the original callback or fulfills the promise but never both.

cb.promise

The returned cb has a promise property that is only defined if the environment has Promise support (i.e. Promise is defined) and the original callback was undefined. When the returned callback is called it fulfills this promise if it is defined or calls the original callback if the promise is undefined.

License

MIT. Copyright (c) Austin Middleton.

Keywords

FAQs

Package last updated on 14 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc